<?php

namespace App\Recharge;

use App\Recharge\Bean\BasicInformation;
use Exception;

class Data
{
    public function __construct(protected BasicInformation $bean)
    {
    }

    /**
     * 易派下单数组组装
     *
     * @return array
     */
    public function yipai(): array
    {
        $please = [
            'businessId'    => $this->bean->getSupplierNum(), //商户号
            'userOrderId'   => $this->bean->getOrderNo(), //订单号
            'goodsId'       => $this->bean->getGoodsId(), //商品编号id
            'userName'      => $this->bean->getAccount(), //要充值的用户
            'gameType'      => $this->bean->getGameType(), //充值的类型
            'goodsNum'      => $this->bean->getRechargeNum(), //充值数量
            'orderIp'       => $this->bean->getIp(), //获取用户当前的ip
            'unitPrice'     => $this->bean->getUnitPrice(), //商品的单价
            'gameName'      => $this->bean->getGoodsName(), //游戏名称
            'gameAcct'      => $this->bean->getGameAcct(), //游戏账号
            'gameArea'      => $this->bean->getGameAreaName(), //游戏区服
            'acctType'      => $this->bean->getAccountType(), //账号类型
            'noticeUrl'     => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        $str = $please['businessId'] . $please['userOrderId'] . $please['goodsId'] . $please['goodsNum'] . $please['orderIp'];
        //生成的sign签名
        $please['sign'] = md5(strtolower($str) . $this->bean->getSecretKey());

        return $please;
    }

    /**
     * 卡盟下单数组组装
     *
     * @return array
     */
    public function kameng(): array
    {
        $array = [
            'customer_id'       => $this->bean->getSupplierNum(), //商户号
            'notify_url'        => $this->bean->getNotifyUrl(), //异步回调地址
            'outer_order_id'    => $this->bean->getOrderNo(),
            'product_id'        => $this->bean->getGoodsId(), //商品编号id
            'quantity'          => $this->bean->getRechargeNum(), //充值数量
            'recharge_account'  => $this->bean->getAccount(), //要充值的用户
            'safe_cost'         => $this->bean->getUnitPrice(),
            'timestamp'         => time(),//时间戳
        ];
        $str = '';
        foreach ($array as $k => $v) {
            $str .= $k . $v;
        }
        $array['sign'] = md5($this->bean->getSecretKey() . $str);
        return $array;
    }

    /**
     * 交易吧下单数组组装
     *
     * @return array
     */
    public function jiaoyiba(): array
    {
        $number = '';
        $faceValue = '';
        if ($this->bean->getGoodsId() == 10){
            $number = 1;
            $faceValue = $this->bean->getRechargeNum() * $this->bean->getStartCharging();
        }
        elseif ($this->bean->getGoodsId() == 13){
            $number = $this->bean->getRechargeNum() * $this->bean->getStartCharging();
            $faceValue  = 1;
        }
        $data = array2json([
            'merAccount'        => $this->bean->getSupplierNum(), //商户号
            'businessType'      => $this->bean->getGoodsId(), //商品编号id
            'merUserAccount'    => '',
            'extendAccount'     => '',
            'attach'            => '',
            'merOrderNo'        => $this->bean->getOrderNo(),
            'merOrderTime'      => date('Y-m-d H:i:s'),//时间
            'rechargeAccount'   => $this->bean->getAccount(), //要充值的用户
            'rechargeValue'     => $faceValue,//面值
            'rechargeNum'       => $number,
            'customerIp'        => $this->bean->getIp(),//获取用户当前的ip
            'notifyUrl'         => $this->bean->getNotifyUrl(), //异步回调地址
            'extendParam'       => [
                'productId'     => $this->bean->getProductId(), //产品id号
                'gameAccount'   => $this->bean->getGameAcct(), //游戏账号
                'gameAreaId'    => $this->bean->getGameAreaId(), //游戏区id
                'gameServerId'  => $this->bean->getGameServerId(), //游戏服id
                'gameAreaName'  => $this->bean->getGameAreaName(), //游戏区名称
                'gameServerName'=> $this->bean->getGameServerName(), //游戏服名称
            ]
        ]);
        $sign = md5(sprintf('data=%s&key=%s', $data, $this->bean->getNotifyUrl()));

        return ['data' => $data, 'sign' => $sign];
    }

    /**
     * 福禄下单数组组装
     *
     * @return array
     */
    public function fulu(): array
    {
        // 组装
        $productType = '';
        if ($this->bean->getProductType() == 0){
            $productType = '直充';
        }
        elseif ($this->bean->getProductType() == 1){
            $productType = '卡密';
        }
        $biz_content = [
            'product_id'        => $this->bean->getGoodsId(), //商品编号id
            'customer_order_no' => $this->bean->getOrderNo(),//订单号
            'charge_account'    => $this->bean->getAccount(), //要充值的用户
            'buy_num'           => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),
            'charge_game_name'  => $this->bean->getGoodsName(),
            'charge_game_region'=> $this->bean->getGameAreaName(), //游戏区名称
            'charge_game_srv'   => $this->bean->getGameServerName(), //游戏服名称
            'charge_type'       => $productType,//充值类型
            'charge_password'   => '',//充值密码
            'charge_ip'         => $this->bean->getIp(),//获取用户当前的ip
            'contact_qq'        => '',//联系QQ
            'contact_tel'       => '',//联系电话
            'remaining_number'  => '',//剩余数量
            'charge_game_role'  => '',//充值游戏角色
            'customer_price'    => $this->bean->getUnitPrice(),
            'external_biz_id'   => ''
        ];
        // 配置
        $array = [
            'app_key'       => $this->bean->getSecretKey(), //开放平台分配给商户的app_key
            'method'        => 'fulu.order.direct.add',//接口方法名称
            'timestamp'     => date('Y-m-d H:i:s'),//时间
            'version'       => '2.0',//调用的接口版本
            'format'        => 'json',//接口请求或响应格式
            'charset'       => 'utf-8',//请求使用的编码格式，如utf-8等
            'sign_type'     => 'md5',//签名加密类型，目前仅支持md5
            'app_auth_token'=> '',//授权码，固定值为'',
            'biz_content'   => array2json($biz_content)
        ];
        $array['sign'] = Sign::currency($array, $this->bean->getSupplierNum());
        return $array;
    }

    /**
     * 硕软
     *
     * @return array
     */
    public function shuoruan(): array
    {
        // 会员充值
        $info1 = [
            'action'        => 'CZ',//指定编码
            'chargeAcct'    => $this->bean->getAccount(), //要充值的用户
            'chargeType'    => 4,//充值类型
            'chargeAmount'  => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),
            'productSn'     => $this->bean->getGoodsId(), //商品编号id
            'retUrl'        => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        $info = [];
        if ($this->bean->getProductType() == 0){
            $info = $info1;
        }
        $info['orderId'] = $this->bean->getOrderNo(); //订单号
        $info = json_encode($info);
        return [
            'agentAccount'  => $this->bean->getSupplierNum(),
            'sign'          => md5($info. $this->bean->getSecretKey()),
            'busiBody'      => json_decode($info,true),
        ];
    }

    /**
     * 迅银下单数组组装
     *
     * @return array
     */
    public function xunyin(): array
    {
        $array = [
            'cpid'          => $this->bean->getSupplierNum(), //商户号
            'gamegoodid'    => $this->bean->getGoodsId(), //商品编号id,
            'createtime'    => date('YmdHis'),
            'account'       => $this->bean->getAccount(), //要充值的用户
            'orderid'       => $this->bean->getOrderNo(), //订单号
            'buynum'        => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),
        ];
        $array['sign'] = md5(urldecode( http_build_query( $array ) ) . $this->bean->getSecretKey());
        $array['buyerIp'] = $this->bean->getIp();
        $array['returnurl'] = $this->bean->getNotifyUrl(); //异步回调地址

        return $array;
    }

    /**
     * @return array
     */
    public function lechong(): array
    {
        $userName = base64_encode($this->bean->getAccount());
        $array = [
            'agentcode' => $this->bean->getSupplierNum(), //商户号
            'code'      => $this->bean->getGoodsId(), //商品编号id,
            'time'      => date('YmdHis'),
            'account'   => $userName,
            'sellerid'  => $this->bean->getOrderNo(), //订单号
            'num'       => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),
            'value'     => $this->bean->getFaceValue() * $this->bean->getRechargeNum() * $this->bean->getStartCharging(),
            'notifyurl' => $this->bean->getNotifyUrl(), //异步回调地址
            'remark'    => urlencode(base64_encode('')),
        ];
        $array['sign'] = md5($array['agentcode'].$array['sellerid'].$array['account'].$array['code']
            .$array['num'].$array['value'].$array['notifyurl'].$array['remark']
            .$array['time']. $this->bean->getSecretKey());

        return $array;
    }

    /**
     * 凤凰数卡
     *
     * @return string
     *
     */
    public function fenghuangshuka(): string
    {
        if ($this->bean->getCateId() == 26){
            $rechargeNum = ($this->bean->getRechargeNum() * $this->bean->getStartCharging()) . 'M';
        } elseif ($this->bean->getCateId() == 25){
            $rechargeNum = $this->bean->getRechargeNum() * $this->bean->getStartCharging();
        } else {
            $rechargeNum = '';
        }
        $please = [
            'userid'        => $this->bean->getSupplierNum(), //商户号
            'productid'     => '',//话费和流量为空
            'price'         => $rechargeNum, //面值 = 数量
            'num'           => '1',//数量 一般为一
            'mobile'        => $this->bean->getAccount(),//充值账号
            'spordertime'   => date('Y-m-d H:i:s',time()),
            'sporderid'     => $this->bean->getOrderNo(), //订单号
        ];

        $sign = urldecode(http_build_query($please).'&key=' . $this->bean->getSecretKey());
        $please['sign'] = md5($sign);
        $please['back_url'] =$this->bean->getNotifyUrl(); //异步回调地址
        $please['flowtype'] = '';
        return urldecode(http_build_query($please));
    }

    /**
     * 承天下
     *
     * @return array
     *
     */
    public function chengtianxia(): array
    {
        $array = [
            'usrid'     => $this->bean->getSupplierNum(), //商户号
            'type'      => $this->bean->getGoodsId(),
            'buynum'    => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),
            'ordernum'  => $this->bean->getOrderNo(), //订单号
            'rcaccount' => $this->bean->getAccount(),//充值账号
            'fromip'    => $this->bean->getIp(),//获取用户当前的ip
            'area'      => $this->bean->getGameAreaName(),
            'returl'    => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        $array['sign'] = md5($array['usrid']. $array['type'].$array['buynum'].$array['ordernum'].$array['rcaccount']
            .$array['fromip']. $this->bean->getSecretKey());

        return $array;
    }

    /**
     * 橙卷
     *
     * @return array
     *
     */
    public function chengjuan(): array
    {
        $array = [
            'timestamp'         => millisecondTimestamp(),
            'app_id'            => $this->bean->getSupplierNum(), //商户号
            'order_no'          => $this->bean->getOrderNo(), //订单号
            'recharge_number'   => $this->bean->getAccount(), //充值账号
            'product_id'        => $this->bean->getGoodsId(), //商品编码
            'amount'            => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),
            'ip'                => $this->bean->getIp(),//获取用户当前的ip
            'notify_url'        => $this->bean->getNotifyUrl(), //异步回调地址
            'version'           => '1.0.0',
            'customer_price'    => $this->bean->getUnitPrice() * 100,
        ];
        ksort($array);
        $data_url = urldecode(http_build_query($array));
        $md5_str  = $data_url.'&key='. $this->bean->getSecretKey();
        $str      = md5($md5_str);
        $sign     = strtoupper($str);
        $array['sign'] = $sign;

        return $array;
    }

    /**
     * 蓝色兄弟
     *
     * @return array
     *
     */
    public function lansexiongdi(): array
    {
        $type = 0;
        $account = $this->bean->getAccount();
        // 判断账号
        if (preg_match("/^1[34578]\d{9}$/", $account)) {
            $type = 1;
        } elseif (preg_match("/^[1-9]\d{4,10}$/", $account)) {
            $type = 2;
        }
        $array = [
            'merchantId'        => $this->bean->getSupplierNum(), //商户号
            'outTradeNo'        => $this->bean->getOrderNo(), //订单号
            'productId'         => $this->bean->getGoodsId(), //商品编码
            'rechargeAccount'   => $account,
            'accountType'       => $type,
            'number'            => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),//充值数量
            'timeStamp'         => time(),
            'notifyUrl'         => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        ksort($array);
        $sign='';
        foreach ($array as $key => $value){
            $sign.=sprintf('%s=%s&', $key, $value);
        }
        $array['sign'] = strtoupper(md5($sign.'key='. $this->bean->getSecretKey()));
        $array['version'] = 1.0;
        $array['extendParameter'] = [];

        return $array;
    }

    /**
     * 严浩
     *
     * @return array
     *
     */
    public function yanhao(): array
    {
        $array = [
            'UserId'        => $this->bean->getSupplierNum(), //商户号
            'TimesTamp'     => millisecondTimestamp(),
            'ProductNumber' => $this->bean->getGoodsId(), //商品编码
            'Count'         => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),//充值数量
            'UserOrderId'   => $this->bean->getOrderNo(), //订单号
            'Account'       => $this->bean->getAccount(),
            'ClientIP'      => $this->bean->getIp(),
            'NotifyUrl'     => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        ksort($array);
        $md5_str = $array['UserId'].$array['Count'].$array['NotifyUrl'].$array['Account'].$array['ClientIP']
            .$array['UserOrderId'].$array['ProductNumber'].$array['TimesTamp']. $this->bean->getSecretKey();
        $str = md5($md5_str);
        $sign = strtoupper($str);
        $array['sign'] = $sign;

        return $array;
    }

    /**
     * 商盟网
     *
     * @return array
     *
     */
    public function shangmengwang(): array
    {
        return [
            'commodityBranchId' => $this->bean->getGoodsId(), //商品编码
            'external_orderno'  => $this->bean->getOrderNo(), //订单号
            'buyCount'          => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),//充值数量
            'callbackUrl'       => $this->bean->getNotifyUrl(), //异步回调地址
            'remark'            => "",
            'externalSellPrice' => $this->bean->getUnitPrice(),
            'template'          => json_encode([urlencode($this->bean->getAccount())]),
        ];
    }

    /**
     * 寓言旺
     *
     * @return array
     *
     */
    public function yuyanwang(): array
    {
        $num = 0;
        if ( $this->bean->getProductType() == 0 ) {
            $num = $this->bean->getFaceValue() * $this->bean->getStartCharging();
        } elseif ($this->bean->getProductType() == 2){
            $num = $this->bean->getRechargeNum() * $this->bean->getStartCharging() . '元';
        } elseif ($this->bean->getProductType() == 3){
            $num = $this->bean->getRechargeNum() * $this->bean->getStartCharging() . 'M';
        }
        $array = [
            'szAgentId'     => $this->bean->getSupplierNum(), //商户号
            'szOrderId'     => $this->bean->getOrderNo(), //订单号
            'szPhoneNum'    => $this->bean->getAccount(),
            'nMoney'        => (int)$num,
            'nSortType'     => $this->bean->getOperatorCode(),
            'nProductClass' => 1,
            'nProductType'  => 1,
            'szProductId'   => $this->bean->getGoodsId(), //商品编码
            'szTimeStamp'   => date('Y-m-d H:i:s'),
            'params'        => json_encode($this->bean->getIp()),
            'szNotifyUrl'   => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        $array['szVerifyString'] = md5('szAgentId='.$array['szAgentId']. '&szOrderId='.$array['szOrderId'].
            '&szPhoneNum='.$array['szPhoneNum']. '&nMoney='.$array['nMoney']. '&nSortType='.$array['nSortType'].
            '&nProductClass='.$array['nProductClass']. '&nProductType='.$array['nProductType']. '&szTimeStamp='.$array['szTimeStamp'].
            '&szKey='. $this->bean->getSecretKey());

        return $array;
    }

    /**
     * 百妙
     *
     * @return array
     */
    public function baimiao(): array
    {
        $key = $this->bean->getSecretKey();
        $platform_id = $this->bean->getSupplierNum();
        $array = [
            'mobile'        => $this->bean->getAccount(),
            'userorderno'   => $platform_id. $this->bean->getOrderNo(),//订单号
            'timestamp'     => millisecondTimestamp(),
            'productid'     => $this->bean->getGoodsId(), //商品编码
            'security'      => $key,
            'platformid'    => $platform_id
        ];
        ksort($array);
        $sign = urldecode(http_build_query($array));
        $array['sign'] = strtoupper(md5($sign));
        $array['cburl'] =$this->bean->getNotifyUrl(); //异步回调地址
        $array['mobile'] = encryptWithOpenssl($array['mobile'], $key, 'DES-ECB');
        $array['productid'] = encryptWithOpenssl($array['productid'], $key, 'DES-ECB');

        return $array;
    }

    /**
     * 旧梦
     *
     * @return array
     */
    public function jiumeng(): array
    {
        $type = 0;
        if (preg_match("/^1[34578]\d{9}$/", $this->bean->getAccount())) {
            $type = 1;
        }
        $array = [
            'merchantId'    => $this->bean->getSupplierNum(),
            'orderNum'      => $this->bean->getOrderNo(),//订单号
            'productCode'   => $this->bean->getGoodsId(), //商品编码
            'chargeAccount' => $this->bean->getAccount(),
            'buyCount'      => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),
            'accountType'   => $type,
            'clientIp'      => $this->bean->getIp(),
            'callBackUrl'   => $this->bean->getNotifyUrl(), //异步回调地址
        ];

        ksort($array);
        $sign_key = $array['accountType'].$array['buyCount'].$array['chargeAccount'].$array['merchantId'].$array['orderNum']
            .$array['productCode']. $this->bean->getSecretKey();
        $array['sign'] = md5($sign_key);

        return $array;
    }

    /**
     * 恒易迅
     *
     * @return array
     *
     */
    public function hengyixun(): array
    {
        $str = '/^[a-zA-Z]|_[a-zA-Z\d_-]{5,19}$/';
        if (preg_match($str, $this->bean->getAccount())) {
            $charge_account_type = '3';
        } else {
            $eg = '/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0-3,5-8])|(18[0-9])|166|198|199|191|195)\d{8}$/';
            $charge_account_type = preg_match($eg, $this->bean->getAccount()) ? '1' : '2';
        }
        $array = [
            'AppKey'            => $this->bean->getSupplierNum(),
            'TimesTamp'         => time(),
            'ProductCode'       => $this->bean->getGoodsId(), //商品编码
            'BuyCount'          => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),
            'MOrderID'          => $this->bean->getOrderNo(),//订单号
            'ChargeAccount'     => $this->bean->getAccount(),
            'ChargeAccountType' => $charge_account_type,
            'CustomerIP'        => $this->bean->getIp(),
            'IsCallback'        => '1',
            'CallBackUrl'       => $this->bean->getNotifyUrl(), //异步回调地址
            'Version'           => '1.0',
        ];
        // sign
        $array['Sign'] = strtoupper(md5($array['AppKey'].$array['BuyCount'].$array['CallBackUrl'].$array['ChargeAccount']
            .$array['CustomerIP'].$array['MOrderID'].$array['ProductCode'].
            $array['TimesTamp'].$array['Version']. $this->bean->getSecretKey()));

        return $array;
    }

    /**
     * @return array
     */
    public function fenxiaoe(): array
    {
        $str = '/^[a-zA-Z]|_[a-zA-Z\d_-]{5,19}$/';
        // 正则
        if (preg_match($str, $this->bean->getAccount())) {
            $charge_account_type = 'WECHAT';
        } else {
            $eg = '/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0-3,5-8])|(18[0-9])|166|198|199|191|195)\d{8}$/';
            if(preg_match($eg, $this->bean->getAccount())){
                $charge_account_type = 'MOBILE';
            }else{
                $charge_account_type = 'QQ';
            }
        }
        $info = [
            'app_order_no'      => $this->bean->getOrderNo(),//订单号
            'goods_sku'         => $this->bean->getGoodsId(), //商品编码
            'goods_count'       => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),
            'charge_query_info' => [
                'charge_account_os_type'    => '',
                'charge_account_type'       => $charge_account_type,
                'charge_account_number'     => $this->bean->getAccount(),
                'charge_type'               => 0,
            ],
            'notify_url'        => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        $array = [
            'msgtype'   => 'request_msg',
            'format'    => 'json',
            'version'   => '1.0',
            'app_id'    => $this->bean->getSupplierNum(),
            'timestamp' => millisecondTimestamp(),
            'method'    => 'order.charge.query',
            'channel'   => 'wap',
            'request_id'=> date('YmdHis').time().rand(0000,9999),
            'message'   => Sign::fxeOpensslMessage($info, $this->bean->getSecretKey()),
        ];
        $array['sign'] = Sign::fxeMakeSign($array, $this->bean->getPrivateKey());

        return $array;
    }

    /**
     * 子轩
     *
     * @return array
     *
     */
    public function zixuan(): array
    {
        list($usec, $sec) = explode(" ", microtime());
        $cn_time = date('YmdHis', time()).round($usec*1000);
        $array = [
            'appId'         => $this->bean->getSupplierNum(),//应用id
            'appSecret'     => $this->bean->getSupplierNum(), //商户密钥
            'outOrderId'    => $this->bean->getOrderNo(), //订单号
            'uuid'          => $this->bean->getAccount(), //充值帐号
            'itemId'        => $this->bean->getGoodsId(), //商品编码
            'itemFace'      => $this->bean->getFaceValue(), //商品面值
            'itemPrice'     => ($this->bean->getUnitPrice() * $this->bean->getRechargeNum() * $this->bean->getStartCharging()),//商品面值
            'amount'        => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),//充值数量,
            'callbackUrl'   => $this->bean->getNotifyUrl(), //异步回调地址
            'timestamp'     => $cn_time,
            'ext1'          => $this->bean->getIp(),
        ];
        ksort($array);
        $array['sign'] =  md5(urldecode(http_build_query($array)));
        unset($array['appSecret']);

        return $array;
    }

    /**
     * 娱尚
     *
     * @return array
     *
     */
    public function yushang(): array
    {
        $array = [
            'AppKey'        => $this->bean->getSupplierNum(), //商户密钥
            'TimesTamp'     => millisecondTimestamp(),
            'ProductCode'   => $this->bean->getGoodsId(), //商品编码
            'BuyCount'      => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),//充值数量,
            'MOrderID'      => $this->bean->getOrderNo(), //订单号
            'ChargeAccount' => $this->bean->getAccount(), //充值帐号
            'CustomerIP'    => $this->bean->getIp(),
            'CallBackUrl'   => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        ksort($array);
        $sign = implode('', $array);
        $sign .= $this->bean->getSecretKey();
        $array['Sign'] = strtoupper(md5($sign));

        return $array;
    }

    /**
     * 微云卡
     *
     * @return array
     *
     */
    public function weiyunka(): array
    {
        $array = [
            'userid'        => $this->bean->getSupplierNum(), //商户密钥
            'outorderno'    => $this->bean->getOrderNo(), //订单号
            'goodsid'       => $this->bean->getGoodsId(), //商品编码
            'buynum'        => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),//充值数量,
            'attach'        => json_encode([$this->bean->getAccount()]),
            'callbackurl'   => $this->bean->getNotifyUrl(), //异步回调地址
            'maxmoney'      => $this->bean->getUnitPrice(),
        ];
        ksort($array); //排序post参数
        $signText='';
        foreach ($array AS $k => $val) { //遍历POST参数
            if ($val == '' || $k == 'sign') continue; //跳过这些不签名
            if ($signText) $signText .= '&'; //第一个字符串签名不加& 其他加&连接起来参数
            $signText .= "$k=$val"; //拼接为url参数形式
        }
        $array['sign'] = md5($signText . $this->bean->getSecretKey());

        return $array;
    }

    /**
     * 乐娱
     *
     * @return array
     *
     */
    public function leyu(): array
    {
        $please = [
            'product_code'  => $this->bean->getGoodsId(), //商品编码
            'notify_url'    => $this->bean->getNotifyUrl(), //异步回调地址
            'buy_num'       => $this->bean->getRechargeNum() * $this->bean->getStartCharging(),//充值数量,
            'account'       => $this->bean->getAccount(),
            'out_trade_no'  => $this->bean->getOrderNo(), //订单号
            'extend'        => ''
        ];
        $array = [
            'app_id'        => $this->bean->getSupplierNum(), //商户密钥
            'method'        => 'hr.order.direct.add',
            'timestamp'     => date('Y-m-d H:i:s',time()),
            'version'       => '1.0',
            'biz_content'   => json_encode($please)
        ];
        ksort($array);
        $sign = '';
        foreach($array as $k => $v){
            $sign .= $k . $v;
        }
        $sign .= $this->bean->getSecretKey();
        $array['sign'] = strtoupper(md5($sign));

        return $array;
    }

    /**
     * 雷鸟
     *
     * @return array
     *
     */
    public function leiniao(): array
    {
        $type = 0;
        if(preg_match("/^1[34578]\d{9}$/", $this->bean->getAccount())){
            $type = 6;
        }else if(preg_match("/^[1-9]\d{4,10}$/", $this->bean->getAccount())){
            $type = 1;
        }else if (preg_match("/^[a-zA-Z][a-zA-Z0-9_-]{5,19}$/", $this->bean->getAccount())){
            $type = 5;
        }
        $array = [
            'merchantNo'            => $this->bean->getSupplierNum(), //商户密钥
            'merchantOrderNo'       => $this->bean->getOrderNo(), //订单号
            'merchantOrderPrice'    => $this->bean->getRechargeNum() * $this->bean->getStartCharging() * $this->bean->getUnitPrice(),
            'merchantPayTime'       => millisecondTimestamp(),
            'userType'              => $type,
            'userId'                => $this->bean->getAccount(),
            'operType'              => 1,
            'serviceProviderType'   => $this->bean->getGoodsId(), //商品编码
            'days'                  => $this->bean->getDashangAccountType(),
            'times'                 => $this->bean->getRechargeNum() * $this->bean->getStartCharging(), //充值数量,
            'appId'                 => '',
            'callbackUrl'           => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        ksort($array);
        $sign_str = urldecode(http_build_query($array));
        $sign_str .= '@' . $this->bean->getSecretKey();
        $sign = md5($sign_str);
        $array['signature'] = $sign;

        return $array;
    }

    /**
     * 西柚
     *
     * @return array
     *
     */
    public function xiyou(): array
    {
        $array = [
            'GID'   => $this->bean->getGoodsId(), //商品编码
            'ID'    => $this->bean->getSupplierNum(), //商户密钥
            'Moery' => bcmul(strval($this->bean->getUnitPrice()), strval($this->bean->getStartCharging()), 4),
            'Num'   => $this->bean->getRechargeNum() * $this->bean->getStartCharging(), //充值数量,
            'PH'    => $this->bean->getAccount(),
            'OID'   => $this->bean->getOrderNo(), //订单号
            'TIM'   => time(),
        ];
        ksort($array);
        $orsg = urldecode(http_build_query($array));
        $array['SG'] = strtoupper(md5($orsg));
        $array['Callback'] =$this->bean->getNotifyUrl(); //异步回调地址

        return $array;
    }

    /**
     * @return array
     *
     */
    public function yunbao(): array
    {
        $array = [
            'user'  => $this->bean->getSupplierNum(), //商户密钥
            'pass'  => $this->bean->getSecretKey(),
            'spid'  => $this->bean->getGoodsId(), //商品编码
            'money' => $this->bean->getUnitPrice() * $this->bean->getStartCharging(),
            'mun'   => $this->bean->getRechargeNum() * $this->bean->getStartCharging(), //充值数量,
            'beizhu'=> base64_encode(json_encode([$this->bean->getAccount()])),
            'yibu'  => $this->bean->getNotifyUrl(), //异步回调地址
            'code'  => '102',
            'order' => $this->bean->getOrderNo(), //订单号
        ];
        ksort($array);
        $array['token'] = md5('user='.$array['user'].'&&pass='.$array['pass']);
        return $array;
    }

    /**
     * @return array
     */
    public function haotian(): array
    {
        return $this->yunbao();
    }

    /**
     * 工匠人心
     *
     * @return array
     *
     */
    public function gongjiangrenxin(): array
    {
        $array = [
            'order_no' => $this->bean->getOrderNo(), //订单号
            'business_number' => $this->bean->getSupplierNum(), //商户密钥
            'good_id' => $this->bean->getGoodsId(), //商品编码
            'account' => $this->bean->getAccount(),
            'num' => (string)($this->bean->getRechargeNum() * $this->bean->getStartCharging()),
            'ip' => $this->bean->getIp(),//获取用户当前的ip,
            'notify_url' => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        ksort($array);
        $array['sign'] = md5(json_encode($array) . $this->bean->getSecretKey());

        return $array;
    }

    /**
     * 云发卡
     *
     * @return array
     *
     */
    public function yunfaka(): array
    {
        return $this->weiyunka();
    }

    /**
     * 漫途科技
     *
     * @return array
     *
     */
    public function mantukeji(): array
    {
        return $this->weiyunka();
    }

    /**
     * 江苏校园
     *
     * @return array
     *
     */
    public function jiangsuxiaoyuan(): array
    {
        return $this->weiyunka();
    }

    /**
     * 清晨网络
     *
     * @return array
     *
     */
    public function qingchenwangluo(): array
    {
        return $this->weiyunka();
    }

    /**
     * 福慧科技
     *
     * @return array
     *
     */
    public function fuhuikeji(): array
    {
        return $this->weiyunka();
    }

    /**
     * 昊天卡卡云
     *
     * @return array
     *
     */
    public function haotiankakayun(): array
    {
        return $this->weiyunka();
    }

    /**
     * 成都雷歌
     *
     * @return array
     *
     */
    public function chengduleige(): array
    {
        $account = (string)$this->bean->getAccount();
        $array = [
            'AppId' => strval($this->bean->getSupplierNum()),
            'SkuType' => 1,
            'Timestamp' => (float)millisecondTimestamp(),
            'SkuId' => (string)$this->bean->getGoodsId(),
            'OutTradeNo' => (string)$this->bean->getOrderNo(),//订单号
            'Number' => (int)($this->bean->getRechargeNum() * $this->bean->getStartCharging()),//充值数量,
            'Account'   => (string)$account,
            'AccountType' => 0,
            'SalesUnitPrice' => floatval($this->bean->getUnitPrice()),
            'NotifyUrl' => $this->bean->getNotifyUrl(), //异步回调地址
        ];
        $array['Sign'] = Sign::chengduleige($array, $this->bean->getSecretKey());

        return $array;
    }

    /**
     * @return array
     *
     */
    public function xqy1(): array
    {
        $data = [
            'customer_id'       => $this->bean->getSupplierNum(),
            'timestamp'         => time(),
            'product_id'        => $this->bean->getGoodsId(),
            'recharge_account'  => $this->bean->getAccount(),
            'quantity'          => $this->bean->getRechargeNum() * $this->bean->getStartCharging(), //充值数量
            'notify_url'        => $this->bean->getNotifyUrl(),
            'outer_order_id'    => $this->bean->getOrderNo(),//订单号
            'safe_cost'         => $this->bean->getUnitPrice(),
            'client_ip'         => $this->bean->getIp(),
        ];
        ksort($data);
        $signStr = $this->bean->getSecretKey();
        foreach ($data as $k => $v) {
            $signStr .= $k . $v;
        }
        $data['sign'] = strtolower(md5($signStr));

        return $data;
    }

    /**
     * @return array
     *
     */
    public function haiwei365(): array
    {
        $data = [
            'app_id'            => $this->bean->getSupplierNum(),
            'timestamp'         => millisecondTimestamp(),
            'product_id'        => $this->bean->getGoodsId(),
            'recharge_number'   => $this->bean->getAccount(),
            'amount'            => $this->bean->getRechargeNum() * $this->bean->getStartCharging(), //充值数量
            'notify_url'        => $this->bean->getNotifyUrl(),
            'order_no'          => $this->bean->getOrderNo(),//订单号
        ];
        ksort($data);
        $sign = urldecode(http_build_query($data)).'&key=' . $this->bean->getSecretKey();
        $data['sign'] = strtoupper(md5($sign));

        return $data;
    }

    /**
     * @return array
     *
     */
    public function tiantianyuntong(): array
    {
        $data = [
            'cid'       => $this->bean->getSupplierNum(),
            'gdid'      => $this->bean->getGoodsId(),
            'accounts'  => $this->bean->getAccount(),
            'amount'    => $this->bean->getRechargeNum() * $this->bean->getStartCharging(), //充值数量
            'nurl'      => $this->bean->getNotifyUrl(),
            'osn'       => $this->bean->getOrderNo(),//订单号
            'cip'       => $this->bean->getIp(),
        ];
        $data['sign'] = md5(
            $data['cid'] . $data['osn'] . $data['gdid'] . $data['accounts'] . $data['amount'] . $this->bean->getSecretKey()
        );
        return $data;
    }
}
